﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace MyTime.Core
{
    /// <summary>
    /// Helper class to perform windows specific stuff, registry edit etc
    /// </summary>
    public static class WindowsHelper
    {
        private const string RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run";
        #region registry write and get
        public static void SetRegistry(string key, string valueName)
        {
            var regKey = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
            regKey.SetValue(key, valueName);
        }
        public static void UnSetRegistry(string valueName)
        {
            var regKey = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
            if (regKey.GetValue(valueName) != null)
                regKey.DeleteValue(valueName);
        }
        public static T GetRegistryValue<T>(string valueName)
        {
            var regKey = Registry.CurrentUser.OpenSubKey(RUN_LOCATION);
            if (regKey == null)
                return default(T);
            return (T)regKey.GetValue(valueName);
        }
        #endregion
    }
}
